package com.stud.common.enums;

/**
 * @author Stud
 * @title X轴类型枚举
 * @desription XXXXX
 * @data 2022-11-16 17:39
 */
public enum XTypeEnum {
    MINUTE("%Y-%m-%d %H:%i", "", "分钟"),
    HOUR("%Y-%m-%d %H", "", "小时"),
    DAY("%Y-%m-%d", "", "天"),
    WEEK("%x-%v", "", "周"),
    MONTH("%Y-%m", "", "月"),
    MONTH_DAY("%m-%d", "", "月-日"),
    SEASON("quarter", "", "季"),
    YEAR("%Y", "", "年"),
    ;

    private final String mysqlFormat;
    private final String tdEngineFormat;
    private final String name;

    XTypeEnum(String mysqlFormat, String tdEngineFormat, String name) {
        this.mysqlFormat = mysqlFormat;
        this.tdEngineFormat = tdEngineFormat;
        this.name = name;
    }

    public String toSql(String field) {
        if (SEASON.equals(this)) {
            return " CONCAT(year(" + field + "), '-', quarter(" + field + ")) ";
        }
        return " date_format(" + field + ",'" + mysqlFormat + "') ";
    }
}
